package com.gao.security.verificationcode.event;

import com.gao.security.verificationcode.base.BaseCodeOperationManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

/**
 * <p></p>
 *
 * @author GaoShuangWen
 */
@Component
public class ValidateCodeRemoveListener implements ApplicationListener<ValidateCodeRemoveEvent> {

    private final Logger log =LoggerFactory.getLogger(this.getClass());
    @Autowired
    private BaseCodeOperationManager codeOperationStrategy;
    @Override
    public void onApplicationEvent( ValidateCodeRemoveEvent validateCodeSuccessEvent) {
        Assert.notNull(validateCodeSuccessEvent,"Event is null");
        // 校验成功触发
        Object source = validateCodeSuccessEvent.getSource();
        String source1 = (String)source;
        codeOperationStrategy.remove((source1));
        log.info("[{source}]:remove success", source1);
    }
}
